<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="操作模块/内容" prop="keyWord">
        <el-input
          v-model="queryParams.keyWord"
          placeholder="请输入操作模块/内容"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          v-hasPermi="['system:operationLog:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
         
          v-hasPermi="['system:operationLog:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
        
          v-hasPermi="['system:operationLog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
        
          v-hasPermi="['system:operationLog:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="operationLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="操作模块" align="center" prop="requestModule" />
      <el-table-column label="操作内容" align="center" prop="requestDesc" />
      <el-table-column label="操作人" align="center" prop="realname" />
      <el-table-column label="操作时间" align="center" prop="requestTime" />
      <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="detailsClick(scope.row)">详情</el-button>
          </template>
        </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />

    <!-- 处置 -->
    <el-dialog :visible.sync="dialogVisible" :title="dialogTitle" width="40%" style="margin-top: 15vh;"
      :before-close="closeDialogVisible">
      <div class="descriptions">
        <el-descriptions :column="2" border>
          <el-descriptions-item>
            <template slot="label"> 操作账号 </template>
            {{ detailsList.username }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 操作IP </template>
            {{ detailsList.ipaddr }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 操作方法 </template>
            {{ detailsList.requestMethod }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 操作时间 </template>
            {{ detailsList.requestTime }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 请求参数 </template>
            {{ detailsList.requestParam }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 请求描述 </template>
            {{ detailsList.requestDesc }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 操作类型 </template>
            {{ detailsList.requestType }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 请求模块 </template>
            {{ detailsList.requestModule }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label"> 操作人 </template>
            {{ detailsList.realname }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getLogs} from "@/api/system/operationLog";

export default {
  name: "Post",
  // dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      operationLogList: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        keyWord: undefined,
      },
      // 详情弹框
      dialogVisible: false,
      detailsList: {},
      dialogTitle: '详情',
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询操作列表 */
    getList() {
      this.loading = true;
      getLogs(this.queryParams).then(response => {
        this.operationLogList = response.body.records;
        this.total = response.body.total;
        this.loading = false;
      });
    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    // 打开详情弹框
    detailsClick(row) {
      this.dialogVisible = true
      this.detailsList = row;
      this.dialogTitle = '详情';
    },
    // 关闭弹框
    closeDialogVisible() {
      this.dialogVisible = false;
    },
  }
};
</script>
